package com.slot.faraohgoldview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.view.View;

public class DoublePanel extends View {
	private Bitmap DPbitmap;
	private Bitmap[] Cardbitmap= new Bitmap[3];
	private Bitmap[] Redbtn= new Bitmap[2];
	private Bitmap[] Blackbtn= new Bitmap[2];
	private float scaleY;
	private float scaleX;
	private Paint paint;
	private int won;
	private int rbtnframe=0;
	private int bbtnframe=0;
	private int cardframe=0;

	public DoublePanel(Context context) {
		super(context);
		
		paint=new Paint();
		paint.setColor(Color.WHITE);
		paint.setTextAlign(Paint.Align.CENTER);
		paint.setTypeface(Typeface.DEFAULT_BOLD);
		paint.setAntiAlias(true);
		
		DPbitmap=BitmapFactory.decodeResource(context.getResources(), R.drawable.dblescr);
		Cardbitmap[0]=BitmapFactory.decodeResource(context.getResources(), R.drawable.card0);
		Cardbitmap[1]=BitmapFactory.decodeResource(context.getResources(), R.drawable.card1);
		Cardbitmap[2]=BitmapFactory.decodeResource(context.getResources(), R.drawable.card2);
		Redbtn[0]=BitmapFactory.decodeResource(context.getResources(), R.drawable.redbtn0);
		Redbtn[1]=BitmapFactory.decodeResource(context.getResources(), R.drawable.redbtn1);
		Blackbtn[0]=BitmapFactory.decodeResource(context.getResources(), R.drawable.blackbtn0);
		Blackbtn[1]=BitmapFactory.decodeResource(context.getResources(), R.drawable.blackbtn1);
	}
	
	@Override
    protected void onSizeChanged(int width, int height, int oldw, int oldh) {
		scaleY = (float) height/480;
		scaleX = (float) width/640;
		paint.setTextSize(25*scaleY);
		DPbitmap = Bitmap.createScaledBitmap(
				DPbitmap, width, (int) (313*scaleY), true);
		for(int i=0;i<3;i++){
			Cardbitmap[i]= Bitmap.createScaledBitmap(
					Cardbitmap[i], (int) (105*scaleX), (int) (154*scaleY), true);
		}
		Redbtn[0] = Bitmap.createScaledBitmap(
				Redbtn[0], (int) (160*scaleX), (int) (113*scaleY), true);
		Redbtn[1] = Bitmap.createScaledBitmap(
				Redbtn[1], (int) (160*scaleX), (int) (113*scaleY), true);
		Blackbtn[0] = Bitmap.createScaledBitmap(
				Blackbtn[0], (int) (160*scaleX), (int) (113*scaleY), true);
		Blackbtn[1] = Bitmap.createScaledBitmap(
				Blackbtn[1], (int) (160*scaleX), (int) (113*scaleY), true);
	}
	
	@Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawBitmap(DPbitmap,0,65*scaleY, null);
        canvas.drawBitmap(Cardbitmap[cardframe],270*scaleX,195*scaleY, null);
        canvas.drawBitmap(Redbtn[rbtnframe],60*scaleX,220*scaleY, null);
        canvas.drawBitmap(Blackbtn[bbtnframe],430*scaleX,220*scaleY, null);
        paint.setColor(Color.rgb(160,64,0));
        canvas.drawText(""+won, 172*scaleX, 132*scaleY, paint);
        canvas.drawText(""+won*2, 477*scaleX, 132*scaleY, paint);
        paint.setColor(Color.WHITE);
        canvas.drawText(""+won, 170*scaleX, 130*scaleY, paint);
        canvas.drawText(""+won*2, 475*scaleX, 130*scaleY, paint);
	}
	
	public void setWon(int w){
		won=w;
		invalidate();
	}
	
	public void setScreen(int rtnb, int bbtn, int card){
		rbtnframe=rtnb;
		bbtnframe=bbtn;
		cardframe=card;
		invalidate();
	}

}
